<template>
    <div class="mod-config">
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
                    <el-form-item>
                        <el-input v-model="dataForm.woDeBaoJia" placeholder="我的报价" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.beiBaoJiaCaiGouID" placeholder="被报价采购id" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.gongYingShuLiang" placeholder="供应数量" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.kuCunDi" placeholder="库存地" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.yaoCaiChanDi" placeholder="药材产地" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.zhiLiangBiaoZhun" placeholder="质量标准" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.yaoCaiTuPian" placeholder="药材图片" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.piaoJu" placeholder="票据" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.ziZhiBiaoZhun" placeholder="资质标准" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.jiYang" placeholder="寄样" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.fuKuan" placeholder="付款" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.baoZhuang" placeholder="包装" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.huoYuanShuoMing" placeholder="货源说明" clearable></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input v-model="dataForm.guanLianYongHu" placeholder="关联用户" clearable></el-input>
                    </el-form-item>
            <el-form-item>
                <el-button @click="getDataList(1)">查询</el-button>
                <el-button type="primary" @click="addOrUpdateHandle()">新增
                </el-button>
                <el-button type="danger" @click="deleteHandle()"
                           :disabled="dataListSelections.length <= 0">批量删除
                </el-button>
            </el-form-item>
        </el-form>
        <el-table
                :data="dataList"
                border
                v-loading="dataListLoading"
                @selection-change="selectionChangeHandle"
                style="width: 100%;">
            <el-table-column
                    label="选中"
                    type="selection"
                    header-align="center"
                    align="center"
                    width="50">
            </el-table-column>
            <el-table-column
                    type="index"
                    label="序号"
                    header-align="center"
                    align="center"
                    width="50">
            </el-table-column>
                    <el-table-column
                            prop="woDeBaoJia"
                            header-align="center"
                            align="center"
                            label="我的报价">
                    </el-table-column>
                    <el-table-column
                            prop="beiBaoJiaCaiGouID"
                            header-align="center"
                            align="center"
                            label="被报价采购id">
                    </el-table-column>
                    <el-table-column
                            prop="gongYingShuLiang"
                            header-align="center"
                            align="center"
                            label="供应数量">
                    </el-table-column>
                    <el-table-column
                            prop="kuCunDi"
                            header-align="center"
                            align="center"
                            label="库存地">
                    </el-table-column>
                    <el-table-column
                            prop="yaoCaiChanDi"
                            header-align="center"
                            align="center"
                            label="药材产地">
                    </el-table-column>
                    <el-table-column
                            prop="zhiLiangBiaoZhun"
                            header-align="center"
                            align="center"
                            label="质量标准">
                    </el-table-column>
                    <el-table-column
                            prop="yaoCaiTuPian"
                            header-align="center"
                            align="center"
                            label="药材图片">
                    </el-table-column>
                    <el-table-column
                            prop="piaoJu"
                            header-align="center"
                            align="center"
                            label="票据">
                    </el-table-column>
                    <el-table-column
                            prop="ziZhiBiaoZhun"
                            header-align="center"
                            align="center"
                            label="资质标准">
                    </el-table-column>
                    <el-table-column
                            prop="jiYang"
                            header-align="center"
                            align="center"
                            label="寄样">
                    </el-table-column>
                    <el-table-column
                            prop="fuKuan"
                            header-align="center"
                            align="center"
                            label="付款">
                    </el-table-column>
                    <el-table-column
                            prop="baoZhuang"
                            header-align="center"
                            align="center"
                            label="包装">
                    </el-table-column>
                    <el-table-column
                            prop="huoYuanShuoMing"
                            header-align="center"
                            align="center"
                            label="货源说明">
                    </el-table-column>
                    <el-table-column
                            prop="guanLianYongHu"
                            header-align="center"
                            align="center"
                            label="关联用户">
                    </el-table-column>
            <el-table-column
                    fixed="right"
                    header-align="center"
                    align="center"
                    label="操作">
                <template slot-scope="scope">
                    <el-button type="text" size="small"
                               @click="infoHandle(scope.row.id)"><i class="el-icon-edit"></i>查看详情</el-button>
                    <el-button type="text" size="small"
                               @click="addOrUpdateHandle(scope.row.id)"><i class="el-icon-edit"></i>修改</el-button>
                    <el-button type="text" size="small"
                               @click="deleteHandle(scope.row.id)"><i class="el-icon-delete"></i>删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                @size-change="sizeChangeHandle"
                @current-change="currentChangeHandle"
                :current-page="pageIndex"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                :total="totalPage"
                layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
        <!-- 弹窗, 新增 / 修改 -->
        <el-dialog title="添加或编辑" :visible.sync="addOrUpdateVisible">
            <el-form :rules="dataRule" :model="dataSaveForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()">
                <el-form-item hidden :label-width="'120px'"  prop="id">
                    <el-input v-model="dataSaveForm.id" autocomplete="off"></el-input>
                </el-form-item>
                        <el-form-item label="我的报价" :label-width="'120px'"  prop="woDeBaoJia">
                            <el-input v-model="dataSaveForm.woDeBaoJia" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="被报价采购id" :label-width="'120px'"  prop="beiBaoJiaCaiGouID">
                            <el-input v-model="dataSaveForm.beiBaoJiaCaiGouID" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="供应数量" :label-width="'120px'"  prop="gongYingShuLiang">
                            <el-input v-model="dataSaveForm.gongYingShuLiang" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="库存地" :label-width="'120px'"  prop="kuCunDi">
                            <el-input v-model="dataSaveForm.kuCunDi" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="药材产地" :label-width="'120px'"  prop="yaoCaiChanDi">
                            <el-input v-model="dataSaveForm.yaoCaiChanDi" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="质量标准" :label-width="'120px'"  prop="zhiLiangBiaoZhun">
                            <el-input v-model="dataSaveForm.zhiLiangBiaoZhun" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="药材图片" :label-width="'120px'"  prop="yaoCaiTuPian">
                            <el-input v-model="dataSaveForm.yaoCaiTuPian" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="票据" :label-width="'120px'"  prop="piaoJu">
                            <el-input v-model="dataSaveForm.piaoJu" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="资质标准" :label-width="'120px'"  prop="ziZhiBiaoZhun">
                            <el-input v-model="dataSaveForm.ziZhiBiaoZhun" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="寄样" :label-width="'120px'"  prop="jiYang">
                            <el-input v-model="dataSaveForm.jiYang" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="付款" :label-width="'120px'"  prop="fuKuan">
                            <el-input v-model="dataSaveForm.fuKuan" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="包装" :label-width="'120px'"  prop="baoZhuang">
                            <el-input v-model="dataSaveForm.baoZhuang" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="货源说明" :label-width="'120px'"  prop="huoYuanShuoMing">
                            <el-input v-model="dataSaveForm.huoYuanShuoMing" autocomplete="off"></el-input>
                        </el-form-item>
                        <el-form-item label="关联用户" :label-width="'120px'"  prop="guanLianYongHu">
                            <el-input v-model="dataSaveForm.guanLianYongHu" autocomplete="off"></el-input>
                        </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="qx()">取 消</el-button>
                <el-button type="primary" @click="dataFormSubmit()">确 定</el-button>
            </div>
        </el-dialog>


        <!-- 弹窗, 新增 / 修改 -->
        <el-dialog title="我的小店收到报价" :visible.sync="infoVisible">
            <div class="mod-config">
                <el-descriptions :column="2" :colon="false" title="设备信息">
                            <el-descriptions-item label="我的报价">{{this.infoList.woDeBaoJia}}</el-descriptions-item>
                            <el-descriptions-item label="被报价采购id">{{this.infoList.beiBaoJiaCaiGouID}}</el-descriptions-item>
                            <el-descriptions-item label="供应数量">{{this.infoList.gongYingShuLiang}}</el-descriptions-item>
                            <el-descriptions-item label="库存地">{{this.infoList.kuCunDi}}</el-descriptions-item>
                            <el-descriptions-item label="药材产地">{{this.infoList.yaoCaiChanDi}}</el-descriptions-item>
                            <el-descriptions-item label="质量标准">{{this.infoList.zhiLiangBiaoZhun}}</el-descriptions-item>
                            <el-descriptions-item label="药材图片">{{this.infoList.yaoCaiTuPian}}</el-descriptions-item>
                            <el-descriptions-item label="票据">{{this.infoList.piaoJu}}</el-descriptions-item>
                            <el-descriptions-item label="资质标准">{{this.infoList.ziZhiBiaoZhun}}</el-descriptions-item>
                            <el-descriptions-item label="寄样">{{this.infoList.jiYang}}</el-descriptions-item>
                            <el-descriptions-item label="付款">{{this.infoList.fuKuan}}</el-descriptions-item>
                            <el-descriptions-item label="包装">{{this.infoList.baoZhuang}}</el-descriptions-item>
                            <el-descriptions-item label="货源说明">{{this.infoList.huoYuanShuoMing}}</el-descriptions-item>
                            <el-descriptions-item label="关联用户">{{this.infoList.guanLianYongHu}}</el-descriptions-item>
                </el-descriptions>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="qxinfo()">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                dataForm: {
                                woDeBaoJia:'',
                                beiBaoJiaCaiGouID:'',
                                gongYingShuLiang:'',
                                kuCunDi:'',
                                yaoCaiChanDi:'',
                                zhiLiangBiaoZhun:'',
                                yaoCaiTuPian:'',
                                piaoJu:'',
                                ziZhiBiaoZhun:'',
                                jiYang:'',
                                fuKuan:'',
                                baoZhuang:'',
                                huoYuanShuoMing:'',
                                guanLianYongHu:'',
                },
                dataSaveForm: {
                                woDeBaoJia:'',
                                beiBaoJiaCaiGouID:'',
                                gongYingShuLiang:'',
                                kuCunDi:'',
                                yaoCaiChanDi:'',
                                zhiLiangBiaoZhun:'',
                                yaoCaiTuPian:'',
                                piaoJu:'',
                                ziZhiBiaoZhun:'',
                                jiYang:'',
                                fuKuan:'',
                                baoZhuang:'',
                                huoYuanShuoMing:'',
                                guanLianYongHu:'',
                },
                dataRule: {
                                woDeBaoJia: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                beiBaoJiaCaiGouID: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                gongYingShuLiang: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                kuCunDi: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                yaoCaiChanDi: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                zhiLiangBiaoZhun: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                yaoCaiTuPian: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                piaoJu: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                ziZhiBiaoZhun: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                jiYang: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                fuKuan: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                baoZhuang: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                huoYuanShuoMing: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                                guanLianYongHu: [
                                {required: true, message: '不能为空', trigger: 'blur'}
                            ],
                },
                dataList: [],
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                dataListLoading: false,
                dataListSelections: [],
                addOrUpdateVisible: false,

                infoList:[],
                infoLoading: false,
                infoVisible: false,

            }
        },

        activated() {
            this.getDataList()
        },
        methods: {
            getDataList(pageIndex) {
                if (pageIndex) {
                    this.pageIndex = pageIndex
                }
                this.dataListLoading = true
                this.$http({
                    url: this.$http.adornUrl('/api-trading/woDeXiaoDian/woDeXiaoDianShouDaoBaoJia/list'),
                        method: 'get',
            params: this.$http.adornParams({
                'page': this.pageIndex,
                        'limit': this.pageSize,
                'woDeBaoJia': this.dataForm.woDeBaoJia,
                'beiBaoJiaCaiGouID': this.dataForm.beiBaoJiaCaiGouID,
                'gongYingShuLiang': this.dataForm.gongYingShuLiang,
                'kuCunDi': this.dataForm.kuCunDi,
                'yaoCaiChanDi': this.dataForm.yaoCaiChanDi,
                'zhiLiangBiaoZhun': this.dataForm.zhiLiangBiaoZhun,
                'yaoCaiTuPian': this.dataForm.yaoCaiTuPian,
                'piaoJu': this.dataForm.piaoJu,
                'ziZhiBiaoZhun': this.dataForm.ziZhiBiaoZhun,
                'jiYang': this.dataForm.jiYang,
                'fuKuan': this.dataForm.fuKuan,
                'baoZhuang': this.dataForm.baoZhuang,
                'huoYuanShuoMing': this.dataForm.huoYuanShuoMing,
                'guanLianYongHu': this.dataForm.guanLianYongHu,
            })
            }).then(({data}) => {
                    if (data && data.code === 0) {
                        this.dataList = data.data.records
                        this.totalPage = Number(data.data.total)
                    } else {
                        this.dataList = []
                        this.totalPage = 0
                    }
                    this.dataListLoading = false
                })
            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val
                this.pageIndex = 1
                this.getDataList()
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val
                this.getDataList()
            },
            // 多选
            selectionChangeHandle(val) {
                this.dataListSelections = val
            },
            qx() {
                this.addOrUpdateVisible = false;

            },
            // 新增 / 修改
            addOrUpdateHandle(id) {
                this.addOrUpdateVisible = true;
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    if (id) {
                        this.$http({
                    url: this.$http.adornUrl(`/api-trading/woDeXiaoDian/woDeXiaoDianShouDaoBaoJia/getById`),
                                method: 'get',
                                params: this.$http.adornParams({"id":id})
                    }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataSaveForm.id = data.data.id
                                this.dataSaveForm.woDeBaoJia = data.data.woDeBaoJia;
                                this.dataSaveForm.beiBaoJiaCaiGouID = data.data.beiBaoJiaCaiGouID;
                                this.dataSaveForm.gongYingShuLiang = data.data.gongYingShuLiang;
                                this.dataSaveForm.kuCunDi = data.data.kuCunDi;
                                this.dataSaveForm.yaoCaiChanDi = data.data.yaoCaiChanDi;
                                this.dataSaveForm.zhiLiangBiaoZhun = data.data.zhiLiangBiaoZhun;
                                this.dataSaveForm.yaoCaiTuPian = data.data.yaoCaiTuPian;
                                this.dataSaveForm.piaoJu = data.data.piaoJu;
                                this.dataSaveForm.ziZhiBiaoZhun = data.data.ziZhiBiaoZhun;
                                this.dataSaveForm.jiYang = data.data.jiYang;
                                this.dataSaveForm.fuKuan = data.data.fuKuan;
                                this.dataSaveForm.baoZhuang = data.data.baoZhuang;
                                this.dataSaveForm.huoYuanShuoMing = data.data.huoYuanShuoMing;
                                this.dataSaveForm.guanLianYongHu = data.data.guanLianYongHu;
                            }
                        })
                    }
                })

            },
            qxinfo() {
                this.infoVisible = false;

            },
            // 新增 / 修改
            infoHandle(id) {
                this.infoVisible = true;
                this.infoList=[];
                this.$http({
            url: this.$http.adornUrl(`/api-trading/woDeXiaoDian/woDeXiaoDianShouDaoBaoJia/getById`),
                        method: 'get',
                        params: this.$http.adornParams({"id":id})
            }).then(({data}) => {
                    if (data && data.code === 0) {
                        this.infoList=data.data;
                    }
                })
            },
            // 删除
            deleteHandle(id) {
                var ids = id ? [id] : this.dataListSelections.map(item => {
                    return item.id
                })
                this.$confirm(`确定要进行删除操作?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$http({
                        url: this.$http.adornUrl('/api-trading/woDeXiaoDian/woDeXiaoDianShouDaoBaoJia/delByIds'),
                            method: 'post',
                            data: this.$http.adornData(ids, false)
                }).then(({data}) => {
                        if (data && data.code === 0) {
                            this.$message({
                                message: '操作成功',
                                type: 'success',
                                duration: 1500,
                                onClose: () => {
                                    this.getDataList()
                                }
                            })
                        } else {
                        this.$message.error(data.msg)
                        }
                    })
                })
            },
            // 表单提交
            dataFormSubmit() {
            this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                    url: this.$http.adornUrl(`/api-trading/woDeXiaoDian/woDeXiaoDianShouDaoBaoJia/save`),
                                method: 'post',
                    data: this.$http.adornData({
                    'id': this.dataSaveForm.id || undefined,
                        'woDeBaoJia': this.dataSaveForm.woDeBaoJia,
                        'beiBaoJiaCaiGouID': this.dataSaveForm.beiBaoJiaCaiGouID,
                        'gongYingShuLiang': this.dataSaveForm.gongYingShuLiang,
                        'kuCunDi': this.dataSaveForm.kuCunDi,
                        'yaoCaiChanDi': this.dataSaveForm.yaoCaiChanDi,
                        'zhiLiangBiaoZhun': this.dataSaveForm.zhiLiangBiaoZhun,
                        'yaoCaiTuPian': this.dataSaveForm.yaoCaiTuPian,
                        'piaoJu': this.dataSaveForm.piaoJu,
                        'ziZhiBiaoZhun': this.dataSaveForm.ziZhiBiaoZhun,
                        'jiYang': this.dataSaveForm.jiYang,
                        'fuKuan': this.dataSaveForm.fuKuan,
                        'baoZhuang': this.dataSaveForm.baoZhuang,
                        'huoYuanShuoMing': this.dataSaveForm.huoYuanShuoMing,
                        'guanLianYongHu': this.dataSaveForm.guanLianYongHu,
                    })
                    }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.addOrUpdateVisible = false
                                        this.getDataList()
                                    }
                                })
                            } else {
                            this.$message.error(data.msg)
                            }
                        })
                    }
                })


            },
        }
    }
</script>
